package main

import (
	"example/gorm/association"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func CreateDB() (db *gorm.DB, err error) {
	// 数据库配置
	dsn := "root:root@tcp(127.0.0.1:3306)/test-gorm"

	// 创建数据库连接实例
	return gorm.Open(mysql.Open(dsn), &gorm.Config{})
}

func main() {
	db, err := CreateDB()

	if err != nil {
		return
	}

	association.QueryWithBelongsTo(db)
}
